$(document).ready(function() {
	//回车模糊查询
	searchEvent();
	//初始化数据
	init(1);			
});
	
//默认加载  
function init(pageNo){
/*	//获取地址
    var areaCode = $('#area .opts .selected').attr("val");
    var areaName = $('#area .opts .selected').html();
    if ( areaCode==undefined || areaCode=='undefined') {
      	areaCode="";
	}	         	
*/
	//获取信息列表
	$("#thislist").html("");
	var search = $("#search").val();
	$.ajax({
		url: urlcore + "/api/contacts/jpa/pageByHouTai?pageNum="+pageNo+"&pageSize="+pageSize+"&search="+search,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				//i表示在data中的索引位置，n表示包含的信息的对象
				$.each(data.data.list,function(i,n){							
				var id = n.id;
					var thislist = 
					'	<tr>'+
					'		<td>'+(i+1)+'</td>'+					
					'		<td>'+n.address.id+'</td>'+
					'		<td>'+n.address.realName+'</td>'+
					'		<td>'+n.address.sex+'</td>'+					
					'		<td>'+n.address.phone+'</td>'+
					'		<td>'+n.address.addressDetail+'</td>'+					
					'		<td>'+			
					'			<a class="btn btn-primary btn-xs" href="address_details.html?id='+id+'">查看详情</a>';
					'		</td>'+
					'	</tr>';
					$('#thislist').append(thislist);	
														
				});
				$('#thiscount').text(data.data.total);
				$("#pager").pager({
					pagenumber: pageNo, 
					pagecount:data.data.pages,
					totalcount:data.data.total,
					buttonClickCallback: PageClick
				}); 
				
			} else if (data.code == 'OVERTIME'){
				var thisUrl = window.location.href;
				if (thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href="login.html";
				}

			} else {
				if (data.msg != '空数据') {
					alert(data.msg)
				}else{
					$('#thiscount').text(0);
				}
			}

		},
		error:function() {
			alert("error");
		}
	});

}
//回调函数  
PageClick = function(pageclickednumber) {  
    init(pageclickednumber); 
}

/**
 * 模糊查询
 */
function searchEvent(){
	$('#search').bind('keypress',function(event){                 
         if(event.keyCode == 13) {
            init(1);
         }  
    });
}
   
